/// 
/// MaDAson - Toolkit for Model Driven Software Development
/// 
/// Copyright [2006] Marcus Lankenau
/// 
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///  
///     http://www.apache.org/licenses/LICENSE-2.0
///  
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
/// 

using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Core;
using NUnit.Framework;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

namespace Madason.MetaModel.Interfaces.Tests
{

	[TestFixture]
	public class TestImportStarUmlDeserialization
	{
		const string starumlXml =
			@"<XPD:PROJECT xmlns:XPD=""http://www.staruml.com"" >" +
			@"<XPD:BODY>" +
			@"	<XPD:OBJ name=""Attributes[3]"" type=""UMLAttribute"" guid=""MthQHkYaEUWciQ6nYk3P9gAA"">" +
			@"		<XPD:ATTR name=""Name"" type=""string"">BoolAttr</XPD:ATTR>" +
			@"		<XPD:ATTR name=""TypeExpression"" type=""string"">bool</XPD:ATTR>" +
			@"		<XPD:REF name=""Owner"">8f0w+y2cj0eyo8EVBE3nQAAA</XPD:REF>" +
			@"		<XPD:OBJ name=""ChildObject"" type=""UMLAttribute"" guid=""xyz""/>" +
			@"	</XPD:OBJ>" +
			@"</XPD:BODY>"+
			@"</XPD:PROJECT>";

		StarUmlModel model = null;

		[SetUp]
		public void Setup()
		{
			StringReader reader = new StringReader(starumlXml);
			XmlSerializer serializer = new XmlSerializer(typeof(StarUmlModel));
			model = serializer.Deserialize(reader) as StarUmlModel;

		}

		[Test]
		public void TestObject()
		{			
			Assert.IsNotNull(model, "Model is not been loaded");
			Assert.AreEqual(1, model.Body.Objects.Count);
			Assert.AreEqual("Attributes[3]", model.Body.Objects[0].Name);
			Assert.AreEqual("UMLAttribute", model.Body.Objects[0].Type);
			Assert.AreEqual("MthQHkYaEUWciQ6nYk3P9gAA", model.Body.Objects[0].Guid);
		}

		[Test]
		public void TestAttribute()
		{
			StarUmlObject obj = model.Body.Objects[0];
			Assert.AreEqual(2, obj.Attributes.Count, "Attribute not found");
			StarUmlAttribute attr = obj.Attributes[0];
			Assert.AreEqual("Name", attr.Name, "Missing attribute name");
			Assert.AreEqual("string", attr.Type, "Missing attribute type");
			Assert.AreEqual("BoolAttr", attr.Value, "Missing attribute value");
		}

		[Test]
		public void TestReferences()
		{
			StarUmlObject obj = model.Body.Objects[0];
			Assert.AreEqual(1, obj.References.Count, "Reference not found");
			StarUmlReference reference = obj.References[0];
			Assert.AreEqual("Owner", reference.Name, "Missing reference name");
			Assert.AreEqual("8f0w+y2cj0eyo8EVBE3nQAAA", reference.Value, "Missing reference target");
			
		}

		[Test]
		public void TestChildObject()
		{
			StarUmlObject obj = model.Body.Objects[0];
			Assert.AreEqual(1, obj.Objects.Count, "Child object not found");
			Assert.AreEqual("ChildObject", obj.Objects[0].Name);
		}
	}
}
